<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="后台管理系统">
    <meta name="description" content="">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <link rel="stylesheet" href="/plugins/layui_v2/css/layui.css">
    <link rel="stylesheet" href="/css/global.css">

    <link rel="stylesheet" type="text/css" href="/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="/css/personal.css" media="all">
    <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_9h680jcse4620529.css">
    <script src="/plugins/layui_v2/layui.js"></script>


<body>
<div class="larry-grid layui-anim layui-anim-upbit larryTheme-A">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote mylog-info-tit">
                <div class="layui-inline">
                    <form class="layui-form" id="roleSearchForm">
                        <div class="layui-input-inline" style="width:110px;">
                            <select name="searchTerm" >
                                <option value="bean_name">Bean名称</option>
                                <option value="method_name">方法名称</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:145px;">
                            <input type="text" name="searchContent" value="" placeholder="请输入关键字" class="layui-input search_input">
                        </div>
                        <a class="layui-btn scheduleSearchList_btn" lay-submit lay-filter="scheduleSearchFilter"><i class="layui-icon larry-icon larry-chaxun7"></i>查询</a>
                    </form>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal add_btn" > <i class="layui-icon larry-icon larry-xinzeng1"></i>新增</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchFail_btn"><i class="layui-icon larry-icon larry-huishouzhan1"></i>删除</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-warm batchPause_btn"  > <i class="layui-icon larry-icon larry-danye"></i>暂停</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn batchResume_btn" style="background-color: #fa6fb7" > <i class="layui-icon larry-icon larry-danye"></i>恢复</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn batchExecute_btn" style="background-color: #55fa80"> <i class="layui-icon larry-icon larry-danye"></i>立即执行</a>
                </div>

            </blockquote>
            <div class="larry-separate"></div>
            <!-- 角色列表 -->
            <div class="layui-tab-item  layui-show" style="padding: 10px 15px;">
                <table id="scheduleTableList" lay-filter="scheduleTableId"></table>
            </div>

        </div>
    </div>
</div>
<script type="text/javascript" th:inline="javascript">
    layui.config({
        base : "/js/"
    }).use(['form', 'table', 'layer','common'], function () {
        var $ =  layui.$,
                form = layui.form,
                table = layui.table,
                layer = layui.layer,
                common = layui.common;

        var loading = layer.load(0,{ shade: [0.3,'#000']});
        /**任务表格加载*/
        table.render({
            elem: '#scheduleTableList',
            url: '/sys/schedule/listAjax',
            id:'scheduleTableId',
            method: 'get',
            height:'full-140',
            skin:'row',
            even:'true',
            size: 'sm',
            cols: [[
                {type:"numbers"},
                {type:"checkbox"},
                {field:'beanName', title: 'Bean名称',align:'center' },
                {field:'methodName', title: '方法名称',align:'center' },
                {field:'params', title: '参数',align:'center' },
                {field:'cronExpression', title: 'cron表达式',align:'center' },
                {field:'status', title: '状态',align:'center',width: '8%',templet: '#statusTpl'},
                {field:'remark', title: '备注',align:'center' },
                {field:'createTime', title: '创建时间',align:'center'},
                {title: '操作', align:'center', width: '10%',toolbar: '#scheduleBar'}

            ]],
            page: true,
            done: function (res, curr, count) {
                common.resizeGrid();
                layer.close(loading);
            }
        });

        /**查询*/
        $(".scheduleSearchList_btn").click(function(){
            var loading = layer.load(0,{ shade: [0.3,'#000']});
            //监听提交
            form.on('submit(scheduleSearchFilter)', function (data) {
                table.reload('scheduleTableId',{
                    where: {
                        key:data.field.searchTerm,
                        value:data.field.searchContent
                    },
                    height: 'full-140',
                    page: true,
                    done: function (res, curr, count) {
                        common.resizeGrid();
                        layer.close(loading);
                    }
                });
            });
        });

        /**新增任务*/
        $(".add_btn").click(function(){
            var url = "/sys/schedule/add";
            common.cmsLayOpen('新增任务',url,'650px','450px');
        });

        /**编辑任务*/
        $(".update_btn").click(function(){
            var url = "/sys/schedule/edit";
            common.cmsLayOpen('编辑任务',url,'650px','450px');
        });

        /**批量删除任务*/
        $(".batchFail_btn").click(function(){
            var checkStatus = table.checkStatus('scheduleTableId');
            if(checkStatus.data.length == 0){
                common.cmsLayErrorMsg("请选择至少1个任务!");
            }else{
                var ids = [];
                $(checkStatus.data).each(function(index, item){
                    ids.push(item.id);
                });
                var url = "/sys/schedule/batchFail";
                var param = {jobIds:ids};
                common.ajaxCmsConfirm('系统提示', '确认要删除任务吗?', url, param);
            }
        });

        /**批量暂停任务*/
        $(".batchPause_btn").click(function(){
            var checkStatus = table.checkStatus('scheduleTableId');
            if(checkStatus.data.length == 0){
                common.cmsLayErrorMsg("请选择至少1个任务!");
            }else{
                var status = false;
                var ids = [];
                $(checkStatus.data).each(function(index, item){
                    ids.push(item.id);
                    //任务已失效
                    if(item.status == 1){
                        status = true;
                        return false;
                    }else{
                        status = false;
                    }
                });
                if(status == true){
                    common.cmsLayErrorMsg("当前选择的任务已暂停");
                    return false;
                }
                var url = "/sys/schedule/batchPause";
                var param = {jobIds:ids};
                common.ajaxCmsConfirm('系统提示', '确认要暂停任务吗?', url, param);
            }
        });


        /**批量立即执行任务*/
        $(".batchExecute_btn").click(function(){
            var checkStatus = table.checkStatus('scheduleTableId');
            if(checkStatus.data.length == 0){
                common.cmsLayErrorMsg("请选择至少1个任务!");
            }else{
                var status = false;
                var ids = [];
                $(checkStatus.data).each(function(index, item){
                    ids.push(item.id);
                    //任务已失效
                    if(item.status == 1){
                        status = true;
                        return false;
                    }else{
                        status = false;
                    }
                });
                if(status == true){
                    common.cmsLayErrorMsg("当前选择的任务已运行");
                    return false;
                }
                var url = "/sys/schedule/batchExecute";
                var param = {jobIds:ids};
                common.ajaxCmsConfirm('系统提示', '确认要运行任务吗?', url, param);
            }
        });

        /**批量恢复任务*/
        $(".batchResume_btn").click(function(){
            var checkStatus = table.checkStatus('scheduleTableId');
            if(checkStatus.data.length == 0){
                common.cmsLayErrorMsg("请选择至少1个任务!");
            }else{
                var ids = [];
                $(checkStatus.data).each(function(index, item){
                    ids.push(item.id);

                });
                var url = "/sys/schedule/batchResume";
                var param = {jobIds:ids};
                common.ajaxCmsConfirm('系统提示', '确认要恢复任务吗?', url, param);
            }
        });

        /**监听工具条*/
        table.on('tool(scheduleTableId)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            console.log(data);
            //编辑任务
            if (layEvent === 'schedule_edit') {
                var id = data.id;
                var url =  "/sys/schedule/edit/"+id;
                common.cmsLayOpen('编辑任务',url,'650px','450px');
            }
        });

    });


</script>

<!-- 任务状态tpl-->
<script type="text/html" id="statusTpl">
    {{# if(d.status == 0){ }}
    <span class="label label-success">正常</span>
    {{# } else if(d.status == 1){ }}
    <span class="label label-danger">暂停</span>
    {{# } else { }}
    {{d.status}}
    {{# }  }}
</script>

<!--工具条 -->
<script type="text/html" id="scheduleBar">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs layui-btn-radius schedule_edit" lay-event="schedule_edit"><i class="layui-icon larry-icon larry-bianji2"></i> 编辑</a>
    </div>
</script>
</body>
</html>